﻿using Newtonsoft.Json;

namespace ufida.u9.cust.dz.beplugin.Utils
{
    internal class JsonUtils
    {
        public static string Serialize(object obj)
        {
            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            };

            // 序列化对象
            string json = JsonConvert.SerializeObject(obj, settings);

            return json.Replace("\\", "");    
        }

        public static T Deserialize<T>(string json)
        {
            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            };

            // 反序列化对象
            T obj = JsonConvert.DeserializeObject<T>(json, settings);

            return obj;
        }
    }
}
